﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data.SqlClient;

namespace ORS.DAL
{
    public class mssqlopr
    {
        private static string scfgcon;
        private string id_user;
        public static System.Data.SqlClient.SqlConnection Conn;
        private System.Data.SqlClient.SqlCommand cmd;
        private System.Data.SqlClient.SqlDataReader reader;
        private System.Data.SqlClient.SqlDataAdapter da;
        private System.Data.DataSet ds;

         static mssqlopr()
        {
           scfgcon = System.Configuration.ConfigurationManager.ConnectionStrings["DB_ConnectionString"].ConnectionString;
           Conn = new SqlConnection(scfgcon);
        }

        public string get_userid(string sqlcmdtext)
        {
            Conn.Open();
            cmd = new SqlCommand(sqlcmdtext, Conn);
            reader = cmd.ExecuteReader();
            if (reader.Read())
              { 
                 id_user = reader.GetString(0).Trim();
               }
            else
              {
                  id_user = null;
               }
            
            reader.Close();
            Conn.Close();
            return id_user;
        }



        public bool find_User(string sqlcmdtext)
         {  
           Conn.Open();
           cmd = new SqlCommand( sqlcmdtext,Conn );
           reader = cmd.ExecuteReader();
           if (reader.Read())
              {
                  reader.Close();
                  Conn.Close();
                  return true;     
               }
           else
              {
                  reader.Close();
                  Conn.Close();
                  return false;
               }
          }

        public System.Data.DataTable GetDataTable(string sqlcmtext)
          {
              da = new SqlDataAdapter(sqlcmtext,Conn);
              ds = new System.Data.DataSet();
              da.Fill(ds);
              return ds.Tables[0];
           }

        public void Modify_Data(string sqlcmd_modi)
        {
            Conn.Open();
            cmd = new SqlCommand(sqlcmd_modi,Conn);
            cmd.ExecuteNonQuery();
            Conn.Close();
        }
    }
}